// ----------------------------------------------------------------------
//  Jack McCaffery
//  11-30-2014
// ----------------------------------------------------------------------

#include "topicModel/fixedParameters.H"
#include "topicModel/parameterGroup.H"


/// \brief Class of model parameters where each row is constrained to sum to one
///	   For now the minimum possible value is zero
///	   SC is the scalar type of the model parameters
template <class SC>
class MultinomialParameters : public ParameterGroup<SC>
{
public:
	~MultinomialParameters ();
	MultinomialParameters ();

	/// \brief Apply gradient holding the sum of each row equal to one
	/// \param gradient_ The gradient to add to the parameters
	/// \param rate_ Rate parameter to scale the gradient
	void applyGradient (FixedParameters<SC> const &gradient_,
			    double rate_);

	/// \brief Set the constraint surface. Each row sums to this value
	/// \param sum_ The value for parameters to sum to
	void setSumValue (SC sum_);

	/// \brief Get the value that rows sum to
	SC sumValue () const;

private:
	/// \brief Project each row onto the boundary of the constrained space
	/// \returns The number of rows that needed to be projected
	int projectOntoBoundaries ();

	/// \brief The constraint value. Each row of data sums to this
	SC sumConstraint;

};
